//
//  ByViewDayEarningPay.m
//  mijifen_ios
//
//  Created by mc on 2017/10/26.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewDayEarningPay.h"

// view
#import "ByViewDayEarningQuery.h"

// cell
#import "ByCellDayEarningPay.h"

@interface ByViewDayEarningPay()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) ByViewDayEarningQuery *queryView;

@property (nonatomic, strong) NSMutableArray *dataArray;
@end

@implementation ByViewDayEarningPay

- (void)setupUI{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundColor = BY_TABLE_COLOR;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self addSubview:self.tableView];
    
    [self fetchData];
}

- (void)setFrame:(CGRect)frame{
    [super setFrame:frame];
    self.tableView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
}
#pragma mark - 获取数据
- (void)fetchData{
    for (int i = 0; i < 10; i ++) {
        ByModelDayEarning *model = [[ByModelDayEarning alloc] init];
        model.prcie = @"2100";
        model.shop_name = @"杭州博✌️";
        model.resource = @"微信退款";
        model.create_time = @"2017-10-26 12:12:10";
        [self.dataArray addObject:model];
    }
    [self.tableView reloadData];
}

#pragma mark - getter
- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ByCellDayEarningPay *cell = [ByCellDayEarningPay cellWithTableView:tableView];
    cell.model = self.dataArray[indexPath.section];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 75;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 30;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
    footerView.backgroundColor = BY_TABLE_COLOR;
    UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH - 20, 20)];
    timeLabel.textAlignment = NSTextAlignmentRight;
    timeLabel.font = FONT(16);
    [footerView addSubview:timeLabel];
    ByModelDayEarning *model = self.dataArray[section];
    timeLabel.text = model.create_time;
    return footerView;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 80)];
        headerView.backgroundColor = BY_TABLE_COLOR;
        ByViewDayEarningQuery *view = [[ByViewDayEarningQuery alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
        view.queryBlock = ^(NSString *year, NSString *month) {
            NSLog(@"%@--%@",year,month);
        };
        [headerView addSubview:view];
        return headerView;
    }
    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 50 + 30;
    }
    return 0.0001;
}


@end
